import Vue from 'vue'

export const SET_MY_WALLET = 'SET_MY_WALLET'
export const UPDATE_BALANCE = 'UPDATE_BALANCE'
export const UPDATE_FRIEND_FUND = 'UPDATE_FRIEND_FUND' //更新签名



export default {
  state: {
    balance: 0,
    friendFund: 0
  },

  mutations: {

    [SET_MY_WALLET](state, myWallet) {
      Object.assign(state, myWallet) //把user的属性复制给state
    },

    [UPDATE_BALANCE](state, payload) {
      state.balance = payload.balance;
      console.log('UPDATE_BALANCE ' + state.balance);
    },

    [UPDATE_FRIEND_FUND](state, payload) {
      state.friendFund = payload.friendFund;
    }

  },
  actions: {
    [SET_MY_WALLET]({
      commit
    }, myWallet) {
      commit(SET_MY_WALLET, myWallet)
    },

    [UPDATE_BALANCE]({
      commit
    }, payload) {
      commit(UPDATE_BALANCE, payload)
    },

    [UPDATE_FRIEND_FUND]({
      commit
    }, payload) {
      commit(UPDATE_FRIEND_FUND, payload)
    }
  }
}
